package com.app.action;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.app.entity.Series;
import com.app.service.SeriesService;

@SuppressWarnings("serial")
@Scope("prototype")
@Controller
public class SeriesAction extends BaseActionSupport<Series>{
	@Autowired
	private SeriesService seriesService;
	
	private Series series = new Series();
	private Collection<Series> seriesList;
	
	public String list(){
		seriesList = seriesService.findSeriesByParameter(series);
		return SUCCESS;
	}	

	public String saveOrUpdate() throws Exception {
		seriesService.SaveOrUpdateSeries(series);
		return list();
	}
	
	public String delete(){
		try {
			seriesService.deleteSeries(series.getValue());
		} catch (Exception ex) {
			logger.debug("删除系列/品名失败，系列/品名可能与产品存在关联，请解除关联后再删除。");
			addActionMessage("删除系列/品名失败，该系列/品名可能与产品存在关联，请解除关联后再删除。");
			ex.printStackTrace();
		}
		return list();
	}
	
	protected void prepareModel() throws Exception {
		if(id != null)
			series = seriesService.load(id);
	}

	public Series getModel() {
		return series;
	}

	public Collection<Series> getSeriesList() {
		return seriesList;
	}

	public void setSeriesList(Collection<Series> seriesList) {
		this.seriesList = seriesList;
	}
}
